

//
//  ErrorView.m
//  Rail
//
//  Created by huyuchen on 2018/8/31.
//  Copyright © 2018年 Hychen. All rights reserved.
//

#import "ErrorView.h"

@interface ErrorView ()
@property (nonatomic, strong) UIImageView *iconView;
@property (nonatomic, strong) UILabel *titleLabel;
@end
@implementation ErrorView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = Color_Background_grey;
        [self setupSubviews];
    }
    return self;
}

- (void)setupSubviews{
    [self addSubview:self.iconView];
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    
    [self addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.right.mas_equalTo(-30);
        make.top.equalTo(self.iconView.mas_bottom).offset(20);
    }];
}

- (UIImageView *)iconView{
    if(!_iconView){
        _iconView = ({
            UIImageView * object = [[UIImageView alloc]init];
            object.image = [UIImage imageNamed:@"icon_empty"];
            object;
       });
    }
    return _iconView;
}

- (UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = ({
            UILabel * object = [[UILabel alloc]init];
            object.font = [UIFont systemFontOfSize:16];
            object.textColor = RGB(167, 160, 157);
            object.numberOfLines = 0;
            object.textAlignment = NSTextAlignmentCenter;
            object;
       });
    }
    return _titleLabel;
}

- (void)setImage:(NSString *)imageName title:(NSString *)title {
    if ([imageName objectIsNotEmpty]) {
        self.iconView.image = [UIImage imageNamed:imageName];
    }
    
    self.titleLabel.text = title;
    
}
@end
